﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace MutilLanguage_Search.Connection
{
    class Web
    {
        public static string RequestVdictEN(string key)
        {
            try
            {
                string source = "http://vdict.com/" + key + ",1,0,0.html";
                WebClient webClient = new WebClient();
                byte[] reqHTML = webClient.DownloadData(source);
                UTF8Encoding objUTF8 = new UTF8Encoding();
                return objUTF8.GetString(reqHTML);
            }
            catch
            {
                return "ERROR";
            }
        }
        public static string RequestVdictVN(string key)
        {
            try
            {
                Console.WriteLine("!");
                string source = "http://vdict.com/" + key + ",2,0,0.html";
                WebClient webClient = new WebClient();
                byte[] reqHTML = webClient.DownloadData(source);
                UTF8Encoding objUTF8 = new UTF8Encoding();
                return objUTF8.GetString(reqHTML);
            }
            catch
            {
                return "ERROR";
            }
        }
        public static string RequestBing(string key)
        {
            try
            {
                string text = "http://www.bing.com/search?q=" + key;
                WebClient webClient = new WebClient();
                byte[] reqHTML = webClient.DownloadData(text);
                UTF8Encoding objUTF8 = new UTF8Encoding();
                return objUTF8.GetString(reqHTML);
            }
            catch
            {
                return "ERROR";
            }
        }
    }
}
